/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package dao.impl;

import java.util.List;
import model.Comentarios;
import model.Historico;
import model.Rating;
import model.Transacoes;
import model.Usuarios;
import model.Veiculos;

/**
 *
 * @author rafael
 */
public final class Delete {

    public static void deletUsuario(Usuarios usuario) {

        Integer pkId = usuario.getPkId();
        List<Historico> historicoCompras = new HistoricoDaoImpl().selectByUsuarioCompras(pkId);
        List<Historico> historicoVendas = new HistoricoDaoImpl().selectByUsuarioVendas(pkId);
        List<Veiculos> listaVeiculos = new VeiculosDaoImpl().selectByUser(pkId);
        List<Comentarios> listaComentarios = new ComentariosDaoImpl().selectByIdUsuario(pkId);
        List<Rating> listaRatings = new RatingDaoImpl().getRatingUsuario(pkId);
        List<Transacoes> listTransacoesComprador = new TransacoesDaoImpl().selectComprador(pkId);
        List<Transacoes> listTransacoesVendedor = new TransacoesDaoImpl().selectVendedor(pkId);

        for (int x = 0; x < listaRatings.size(); x++) {
            new RatingDaoImpl().eliminar(listaRatings.get(x));
        }
        for (int x = 0; x < historicoCompras.size(); x++) {
            new HistoricoDaoImpl().eliminar(historicoCompras.get(x));
        }
        for (int x = 0; x < historicoVendas.size(); x++) {
            new HistoricoDaoImpl().eliminar(historicoVendas.get(x));
        }
        for (int x = 0; x < listaComentarios.size(); x++) {
            new ComentariosDaoImpl().eliminar(listaComentarios.get(x));
        }
        for (int x = 0; x < listTransacoesComprador.size(); x++) {
            new TransacoesDaoImpl().eliminar(listTransacoesComprador.get(x));
        }
        for (int x = 0; x < listTransacoesVendedor.size(); x++) {
            new TransacoesDaoImpl().eliminar(listTransacoesVendedor.get(x));
        }
        for (int x = 0; x < listaVeiculos.size(); x++) {
            deleteVeiculo(listaVeiculos.get(x));
        }

        new UsuariosDaoImpl().eliminar(usuario);
    }

    public static void deleteVeiculo(Veiculos veiculo) {

        List<Rating> listRating = new RatingDaoImpl().getRatingVeiculos(veiculo.getPkVeiculos());
        List<Comentarios> listaComentarios = new ComentariosDaoImpl().selectAll(veiculo.getPkVeiculos());
        Transacoes transacoesTemp = new TransacoesDaoImpl().selectVeiculo(veiculo.getPkVeiculos());

        for (int x = 0; x < listRating.size(); x++) {
            new RatingDaoImpl().eliminar(listRating.get(x));
        }
        for (int x = 0; x < listaComentarios.size(); x++) {
            new ComentariosDaoImpl().eliminar(listaComentarios.get(x));
        }
        if (transacoesTemp != null) {
            new TransacoesDaoImpl().eliminar(transacoesTemp);
        }
        new VeiculosDaoImpl().eliminar(veiculo);
        new RedimensionarDaoImpl().deletarArquivosImagens(veiculo.getPkVeiculos());
    }
}
